<!--{template /module/admin/view/head}-->
<div id="left_layout">
	<div id="main_content" class="container-fluid">
		<!--{template /module/admin/view/head_nav}-->
		<div class="row-fluid">
			<form method="post" action="{$ADMIN_SCRIPT}/note/record/{$dispatches[method]}&id={$_var[gp_id]}&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}" onsubmit="javascript:return check_form(this);">
			<input type="hidden" name="formsubmit" value="yes" />
				<div class="well widget">
					<div class="widget-header">
						<p class="text">* {lang admin.validate.require}</p>
					</div>
					<div class="widget-content">
						<fieldset>
							<label>{lang note.record_edit.view.note.label} *</label>
							<select name="sltNoteId" id="slt_note_id">
			                	<option value="0">{lang note.record_edit.view.note.select}</option>
			                	<!--{loop $note_list $key $note}-->
			                	<option value="{$note[NOTEID]}" {if $note[NOTEID] == $record[NOTEID]}selected="selected"{/if}>{$note[TITLE]}</option>
			                	<!--{/loop}-->
			                </select>
			                <span class="help-inline">{lang note.record_edit.view.note.tips}</span>
			                <br/>
			                <span id="div_note_info" class="help-inline"></span>
			                
							<div id="tr_username" style="display:none;">
								<label>{lang note.record_edit.view.username.label} *</label>
								<input type="text" class="input-medium"name="txtUserName" placeholder="{lang note.record_edit.view.username.placeholder}..."  maxlength="20" value="{$record[USERNAME]}" /> 
								<span class="help-inline">{lang note.record_edit.view.username.tips}</span>
							</div>
							
							<label>{lang note.record_edit.view.title.label} *</label>
							<input type="text" class="input-xlarge" name="txtTitle" placeholder="{lang note.record_edit.view.title.placeholder}..."  maxlength="50" value="{$record[TITLE]}" /> 
							<span class="help-inline">{lang note.record_edit.view.title.tips}</span>
							
							<div id="tr_department" style="display:none;">
								<label>{lang note.record_edit.view.department.label} *</label>
								<input type="text" class="input-large" name="txtDepartment" placeholder="{lang note.record_edit.view.department.placeholder}..."  maxlength="50"  value="{$record[DEPARTMENT]}"  /> 
								<span class="help-inline">{lang note.record_edit.view.department.tips}</span>
							</div>
							
							<div id="tr_place" style="display:none;">
								<label>{lang note.record_edit.view.place.label} *</label>
								<input type="text" class="input-xlarge"name="txtPlace" placeholder="{lang note.record_edit.view.place.placeholder}..."  size="40" maxlength="100" value="{$record[PLACE]}" /> 
								<span class="help-inline">{lang note.record_edit.view.place.tips}</span>
							</div>
							
							<div id="tr_email" style="display:none;">
								<label>{lang note.record_edit.view.email.label} *</label>
								<input type="text" class="input-xlarge" name="txtEmail" placeholder="{lang note.record_edit.view.email.placeholder}..."  maxlength="100"  value="{$record[EMAIL]}" /> 
								<span class="help-inline">{lang note.record_edit.view.email.tips}</span>
							</div>
							
							<div id="tr_connect"style="display:none;">
								<label>{lang note.record_edit.view.phone.label} *</label>
								<input type="text" class="input-medium"name="txtConnect" placeholder="{lang note.record_edit.view.phone.placeholder}..."  maxlength="50" value="{$record[CONNECT]}" /> 
								<span class="help-inline">{lang note.record_edit.view.phone.tips}</span>
							</div>
							
							<label>{lang note.record_edit.view.keywords.label}</label>
							<input type="text" name="txtKeywords" maxlength="30" class="input-xxlarge" value="{$record[KEYWORDS]}"/>
							<span class="help-inline">{lang note.record_edit.view.keywords.tips}</span>
							
							<label>{lang note.record_edit.view.content.label}</label>
							<textarea class="span8" rows="8" cols="45" name="txtContent">{$record[CONTENT]}</textarea>
							<span class="help-inline">{lang note.record_edit.view.content.tips}</span>
							
							<label>{lang note.record_edit.view.reply.label}</label>
							<textarea class="span8" rows="4" cols="45" name="txtReply">{$record[REPLY]}</textarea>
							
							<hr/>
							<label>{lang note.record_edit.view.open.label}</label>
							<label class="checkbox inline">
								<input type="radio" name="rdoIsOpen" class="fancy" value="1"  {if $record['ISOPEN'] == 1}checked="checked"{/if} /> {lang note.record_edit.view.open.enabled} 
							</label>
							<label class="checkbox inline">
								<input type="radio" name="rdoIsOpen" class="fancy" value="0" {if $record['ISOPEN'] == 0}checked="checked"{/if} /> {lang note.record_edit.view.open.disabled}
							</label>
			            	
			            	<hr/>
							<label>{lang note.record_edit.view.commend.label}</label>
							<select name="eleIsCommend">
						        <option value="0">{lang note.record_edit.view.commend.select.0}</option>
						        <option value="3" {if $record['ISCOMMEND'] == 3}selected="selected"{/if}>{lang note.record_edit.view.commend.select.3}</option>
						        <option value="2" {if $record['ISCOMMEND'] == 2}selected="selected"{/if}>{lang note.record_edit.view.commend.select.2}</option>
						        <option value="1" {if $record['ISCOMMEND'] == 1}selected="selected"{/if}>{lang note.record_edit.view.commend.select.1}</option>
					        </select>
					        <span class="help-inline">{lang note.record_edit.view.commend.tips}</span>
							
						</fieldset>
						<hr/>
						<fieldset>
							<!--{if $dispatches['method'] == '_pub'}-->
							<button type="submit" class="btn btn-small btn-primary" {$dispatches[operations][add]}>{lang admin.operation.submit}</button>
							<!--{else}-->
							<button type="submit" class="btn btn-small btn-primary" {$dispatches[operations][edit]}>{lang admin.operation.submit}</button>
							<!--{/if}-->
							<button type="reset" class="btn btn-small">{lang admin.operation.reset}</button>
							<button type="button" class="btn btn-small" onclick="javascript:location.href='{$ADMIN_SCRIPT}/note/record&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}';">{lang admin.operation.go.back}</button>
						</fieldset>
					</div>
				</div>	
			</form>
		</div>
	</div>
</div>
<script>
var note_list = new Array();
{loop $note_list $key $note}

note_list[{$note[NOTEID]}] = {
	GUEST:{$note[GUEST]}, 
	BEGINDATE: '{$note[BEGINDATE]}', 
	ENDDATE: '{$note[ENDDATE]}', 
	NEEDS: {
		department: {echo $note[NEEDS][department] + 0;}, 
		place: {echo $note[NEEDS][place] + 0;}, 
		email: {echo $note[NEEDS][email] + 0;}, 
		connect: {echo $note[NEEDS][connect] + 0;} 
	}
};

{/loop}
  
function check_form(frm){
    if(frm.sltNoteId.selectedIndex == 0){
    	$(frm.sltNoteId).next('.help-inline').css('color', 'red');
    	frm.sltNoteId.focus();
    	return false;
    }
    
    var noteid = frm.sltNoteId.options[frm.sltNoteId.selectedIndex].value;
    noteid = noteid - 0;
    
    if(noteid == 0){
    	$(frm.sltNoteId).next('.help-inline').css('color', 'red');
    	frm.sltNoteId.focus();
    	return false;
    }
    
    var cnote = note_list[noteid];
    
    if(cnote.GUEST == 0 && frm.txtUserName.value.trim().length == 0){
    	$(frm.txtUserName).next('.help-inline').css('color', 'red');
    	frm.txtUserName.focus();
    	return false;
    }
    
    if(frm.txtTitle.value.trim().length == 0){
    	$(frm.txtTitle).next('.help-inline').css('color', 'red');
    	frm.txtTitle.focus();
    	return false;
    }
    
    if(cnote.NEEDS.department && frm.txtDepartment.value.trim().length == 0){
    	$(frm.txtDepartment).next('.help-inline').css('color', 'red');
    	frm.txtDepartment.focus();
    	return false;
    }
    
    if(cnote.NEEDS.place && frm.txtPlace.value.trim().length == 0){
    	$(frm.txtPlace).next('.help-inline').css('color', 'red');
    	frm.txtPlace.focus();
    	return false;
    }
    
    if(cnote.NEEDS.email && frm.txtEmail.value.trim().length == 0){
    	$(frm.txtEmail).next('.help-inline').css('color', 'red');
    	frm.txtEmail.focus();
    	return false;
    }
    
    if(cnote.NEEDS.email && !frm.txtEmail.value.trim().isEmail()){
    	$(frm.txtEmail).next('.help-inline').css('color', 'red');
    	frm.txtEmail.focus();
    	return false;
    }
    
    if(cnote.NEEDS.connect && frm.txtConnect.value.trim().length == 0){
    	$(frm.txtConnect).next('.help-inline').css('color', 'red');
    	frm.txtConnect.focus();
    	return false;
    }
    
    if(frm.txtContent.value.trim().length == 0){
    	$(frm.txtContent).next('.help-inline').css('color', 'red');
    	frm.txtContent.focus();
    	return false;
    }

    return true;
}
  
function change_note_info(noteid){
  	$('#div_note_info').html('');
  	$('#tr_username').hide();
	$('#tr_department').hide();
	$('#tr_place').hide();
	$('#tr_email').hide();
	$('#tr_connect').hide();

	if(noteid > 0 && note_list[noteid]){
		var tempHTML = '';
		if(note_list[noteid].BEGINDATE) tempHTML += '{lang note.record_edit.validate.begindate}' + note_list[noteid].BEGINDATE + '；';
		if(note_list[noteid].ENDDATE) tempHTML += '{lang note.record_edit.validate.enddate}' + note_list[noteid].ENDDATE + '；';
		
		$('#div_note_info').html(tempHTML);
		if(note_list[noteid].GUEST == 0) $('#tr_username').show();
		if(note_list[noteid].NEEDS.department) $('#tr_department').show();
		if(note_list[noteid].NEEDS.place) $('#tr_place').show();
		if(note_list[noteid].NEEDS.email) $('#tr_email').show();
		if(note_list[noteid].NEEDS.connect) $('#tr_connect').show();
	}
}

$(function(){
	$('.fancy').uniform();
	
	$('fieldset input,textarea,select').blur(function(){
		$(this).next('.help-inline').css('color', '#333');
	});
	
	$('#slt_note_id').change(function(){
		var noteid = $(this).val();
		noteid = noteid - 0;
		change_note_info(noteid);
	});
	
	{if $record}
	change_note_info({$record[NOTEID]});
	{/if}
});
   
</script>
<!--{template /module/admin/view/foot}-->